package linechart;

import common.ChartDemo;
import common.ChartUtil;
import dataset.SampleXYDataset;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.general.Dataset;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

import java.awt.geom.Rectangle2D;

public class LineChartDemo4 extends ChartDemo {

    public LineChartDemo4(String title) {
        super(title);
    }

    @Override
    protected Dataset createDataset() {
        return new SampleXYDataset();
    }

    @Override
    protected JFreeChart createChart(Dataset dataset) {
        XYDataset xyDataset = (XYDataset) dataset;
        JFreeChart jFreeChart = ChartFactory.createXYLineChart("Line Chart Demo 4", "X",
                "Y", xyDataset, PlotOrientation.VERTICAL,
                true, true, false);

        XYPlot xyPlot = (XYPlot) jFreeChart.getPlot();
        xyPlot.setDomainPannable(true);
        xyPlot.setRangePannable(true);
        xyPlot.setDomainZeroBaselineVisible(true);
        xyPlot.setRangeZeroBaselineVisible(true);
        xyPlot.getDomainAxis().setLowerMargin(0.0D);
        xyPlot.getDomainAxis().setUpperMargin(0.0D);

        XYLineAndShapeRenderer xyLineAndShapeRenderer = (XYLineAndShapeRenderer) xyPlot.getRenderer();
        xyLineAndShapeRenderer.setLegendLine(new Rectangle2D.Double(-4D, -3D, 8D, 6D));

        return jFreeChart;
    }

    public static void main(String[] args) {
        LineChartDemo4 demo1 = new LineChartDemo4("LineChartDemo4");
        ChartUtil.showChartDemo(demo1);
    }
}
